<?php
/**
 * @Author: anchen
 * @Date:   2019-03-05 15:16:08
 * @Last Modified by:   anchen
 * @Last Modified time: 2019-03-20 16:55:10
 */
namespace app\chat\controller;

use think\Controller;
use think\Db;

class Index extends Controller
{
    
    //登录
    public function login(){
        return $this->fetch();
    }

    //dologin
    public function dologin(){
        $code = 202;
        $msg = '网络异常';
        $data = '';
        $userPhone = input('mobile');
        $checkCode = input('checkCode');
        if(empty($userPhone) || empty($checkCode) ){
            $msg = '参数异常';
            goto end;
        }
        $userInfo = db('member')->where(['mobile'=>$userPhone])->find();
        // $userModel = model('Member');

        //判断是否判断的手机
        //$userInfo = $userModel->getMember(['mobile'=>$userPhone],'id,mobile');
        if(!$userInfo){
            
            $insertData = [
                'mobile' => $userPhone,
                'username' => $userPhone,
                'ctime' => time(),
                'utime' => date('Y-m-d H:i:s'),
                'status' => 1,
                'ua' => getOS()

            ];
            $bl = db('member')->insert($insertData);
            $userInfo = $insertData;
        }

        session('user',$userInfo['mobile']);
        $code = 200;
        $data['userinfo'] = $userInfo;
        $msg = 'success';

        end:;
        return returnJson($data,$code,$msg);
    }

    //首页
    public function index(){
        return $this->fetch();
    }

    //详情
    public function detail(){
        
        return $this->fetch();
    }

    //发送聊天
    //
    public function do_chat(){
        $mobile = session('user');
        $content = input('content');
    }

}